package gti310.tp3.writer;
import java.io.*;
import java.util.*;

import gti310.tp3.solver.T;

public class ConcreteWriter implements Writer<T>{

	/**
	 * Constructeur de la classe par défaut
	 */
	public ConcreteWriter(){};

	/**
	 * Write the given object's data to file.
	 * @param filename The complete path to the file that will be created.
	 * @param output The data which will be written to the file.
	 */
	public void write(String filename, T output) {

		try{

			FileWriter fw = new FileWriter(filename);
			BufferedWriter bw = new BufferedWriter(fw);
			
			//Ecriture de la solution sour le format:
			//<départ><espace><sommet><espace><sommet>...<départ>
			for(ArrayList<Integer> p : output.getPath())
			{
				for(Integer i : p)
				{
					System.out.print(i + " ");
					bw.write(""+i+" ");
				}
				System.out.println("\n");
				bw.write("\n");
			}
			
			
			
			bw.close();
			

		}catch (IOException e) {
			System.out.println("Error while writing in the file" 
					+ e.getMessage()); 
		}

	}
}
